package com.kgc.controller;

import com.kgc.bean.Jek;
import com.kgc.common.Dto;
import com.kgc.feign.FeignService;
import com.kgc.pojo.DmUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class DmUserConsumerController {
    @Autowired
    private FeignService feignService;

    /**
     * 通过token 获取用户信息
     * @param key
     * @return
     */
    @RequestMapping(value = "/consumer/v/loadCurrentUserByToken", method = RequestMethod.POST)
    public Dto loadCurrentUserByToken(@RequestParam String key){
       return feignService.loadCurrentUserByToken(key);
    }

    /**
     * 输入账号密码登录
     * @param dmUser
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/consumer/p/login", method = RequestMethod.POST)
    public Dto login(@RequestBody DmUser dmUser) throws Exception{
        return feignService.login(dmUser);
    }

    /**
     * 检查 手机号或者邮箱是否能注册
     * @param phone
     * @return
     */
    @RequestMapping(value = "/consumer/p/checkEmail", method = RequestMethod.POST)
    public Dto checkEmail(@RequestParam String phone){
        return feignService.checkEmail(phone);
    }

    /**
     * 注册时发送的验证码
     * @param phone
     * @return
     */
    @RequestMapping(value = "/consumer/p/code", method = RequestMethod.POST)
    public Dto code(@RequestParam String phone){
        return feignService.code(phone);
    }

    /**
     * 通过验证码 注册
     * @param jek
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/consumer/p/register", method = RequestMethod.POST)
    public Dto register(@RequestBody Jek jek) throws Exception{
        return feignService.register(jek);
    }

    /**
     * 发送验证码
     * @param phone
     * @return
     */
    @RequestMapping(value = "/consumer/user/msg", method = RequestMethod.POST)
    public Dto msg(@RequestParam String phone){
        return feignService.msg(phone);
    }

    /**
     * 通过验证码登录
     * @param jek
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/consumer/user/login", method = RequestMethod.POST)
    public Dto msg(@RequestBody Jek jek) throws Exception{
        return feignService.login_user(jek);
    }
}
